package cn.demo.controller;

import cn.demo.entity.Book;
import cn.demo.service.BookServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@Api(description = "Book  类")
@RequestMapping("/Books")
public class BookController {

    @Autowired
    BookServiceImpl bookServiceImpl;

    @ApiOperation("添加BOOk方法")
    @GetMapping("/book")
    public  ModelAndView   addBook(ModelAndView  model){
    Book book = new Book(5,"Springcloud","bdqn",2);
  //      System.out.println("添加："+bookService.addBook(book));
        List bookList = bookServiceImpl.getAllBook();
        System.out.println("查询所有："+bookServiceImpl.getAllBook().toString());
        System.out.println("按ID查询："+bookServiceImpl.getBookById(1).toString());
        model.addObject("bookList",bookList);
        model.setViewName("index");
        return  model;
    }
}
